<?php 

Class voteController extends appController
{
	
	public function info()
	{
		
		if($_GET['id']>0)
		{
			
			$vote = Model('vote')->getVote($_GET['id']);
			
			
			
			$this->assign("vote", $vote);
		}
		
		$this->display('info.html');
	}
	
	/**
	 * 显示版块列表
	 */
	public function index()
	{
		$page = yf_empty(intval($_GET['page']), 1, true);
		$ad_list = Model('vote')->ad_list($page);
		$this->assign('ad_list', $ad_list['data']);
		$this->assign('user_list_page', $ad_list['pagelink']);
		$this->display('index.html');
	}
	
	public function del()
	{
		$id=isset($_REQUEST['id'])?$_REQUEST['id']:'';
	
		if(is_array($id))
		{
			foreach($id as $k=>$v)
			{
				$result=Model('suipai')->del_vote($v,"vote");
			}
		}
		else
		{
			$id=intval($id);
	
			$result=Model('suipai')->del_vote($id,"vote");
		}
		
		$data['error']=0;
		$data['content']="删除成功";
		
		$this->showMsg($data);
	
	}
	
	
	
	
	/**
	 * 更新版块详细内容
	 */
	public function updateVote()
	{
		
	
		$title = yf_empty($_POST['name'], Lang('标题不能为空'));
		
		//$id = yf_empty(intval($_POST['id']), '', true);
		//$info['modified'] = yf_time();
		$data = array('error' => 1, 'content' => '');
		
		$info['name'] = $title;
		$info['status'] = $_POST['status'];
		$info['dotime1'] = strtotime($_POST['dotime1']);
		$info['dotime2'] = strtotime($_POST['dotime2']);
		
		//yf_get_timezone_offset($remote);
// 		echo $info['dotime1'].$_POST['dotime1'];
		
		$result = Model('vote')->updateVote($info, $_POST['id']);
		
		$id = $_POST['id']>0?$_POST['id']:$result;
		
		
		
		if( $_POST['joinnums'] ==0 )
		{
			
			
			foreach ($_POST['option_name'] as $k => $v)
			{
				if($v=="")
				{
					$data['content']="选项不能为空";
					$this->showMsg($data);
				}
			}
			
			$result = Model('vote')->updateOption($_POST['option_name'],$id);
			
		}
		$data['error']=0;
		$data['content']=Lang('SUCCESS_EDIT');
		
		$this->showMsg($data);
	}
	
}